{extend name="layout/base" /}
<!-- 标题 -->
{block name="title"}数据备份{/block}
<!-- CSS -->
{block name="css"}{/block}
<!-- 具体内容 -->
{block name="content"}
<h2 class="header-dividing">数据备份 <small>Data backup</small></h2>
<div class="navbar navbar-default navbar-content">
    <div class="collapse navbar-collapse">
        <ul class="nav navbar-nav">
            {if(check_auth('databk-create'))}<li><a class="databk-create" data-url="{:url('@admin/databk/create')}"> <i class="icon icon-database"></i> 新建备份</a></li>{/if}
        </ul>
        <!-- 导航中的表单 -->
        <form class="navbar-form navbar-left" role="search" action="{:url('@admin/databk')}" method="get">
            <input type="text" class="form-control" placeholder="搜索" name="keywords" value="{$keywords}">
            <button type="submit" class="btn btn-default">搜索</button>
        </form>
    </div>
</div>
<div class="panel">
    <table class="table datatable table-fixed" data-checkable="true" data-check-by-click-row="false" data-fixed-left-width="50" data-fixed-right-width="160">
        <thead>
            <tr>
                <th data-width="50">#</th>
                <th>备份名称</th>
                <th>备份时间</th>
                <th>文件大小</th>
                <th data-width="80" class="text-center">下载</th>
                <th data-width="80" class="text-center">删除</th>
            </tr>
        </thead>
        <tbody>
            {volist name="list" id="vo" key="i"}
            <tr data-id="{$vo['name']}">
                <td>{$i}</td>
                <td>{$vo['name']}</td>
                <td>{:date("Y-m-d H:i:s", $vo['atime'])}</td>
                <td>{$vo['size']}</td>
                <td class="text-center">{if(check_auth('databk-download'))}<a href="{:url('@admin/databk/download', 'name='.$vo['name'])}" target="_blank">下载</a>{/if}</td>
                <td class="text-center">{if(check_auth('databk-delete'))}<a class=" delete" data-url="{:url('@admin/databk/delete', 'name='.$vo['name'])}">删除</a>{/if}</td>
            </tr>
            {/volist}
        </tbody>
    </table>
    {empty name="list"}
    <div class="mb20 mt20 text-center">
        {if ($keywords!='')}
        未搜索到 “{$keywords}” 相关的备份 &nbsp; <a href="{:url('@admin/databk')}">查看全部备份</a>
        {else /}
        暂未添加备份
        {/if}
    </div>
    {/empty}
    {notempty name="list"}
    <div class="mb10 ml10">
        {if(check_auth('databk-delete'))}
        <button class="btn btn-danger databk-delete" type="button" data-url="{:url('@admin/databk/delete')}">删除备份</button>
        {/if}
    </div>
    {/notempty}
</div>
{/block}


<!-- JS -->
{block name="js"}
<script type="text/javascript">
$(document).ready(function() {

    $("a.databk-create").click(function(event) {
        sxj.ajax_get($(this).data('url'));
    });

    $('.databk-delete').click(function(event) {
        var $url = $(this).data('url');
        // 获取数据表格实例对象
        var myDatatable = $('table.datatable').data('zui.datatable');
        // 获取行选中数据
        var checksStatus = myDatatable.checks;

        if (checksStatus == undefined) {
            return sxj.msg_error('请先选择内容！');
        }
        bootbox.confirm({
            message: "确定要删除选中的内容？",
            callback: function(result) {
                if (result) {
                    sxj.ajax_del($url + '?name=' + checksStatus.checks.toString());
                }
            }
        });
    });
});
</script>
{/block}